#include "copyrightdialog.h"
#include "ui_copyrightdialog.h"

CopyRightDialog::CopyRightDialog(int styleId,QWidget *parent) :
    QDialog(parent),
    ui(new Ui::CopyRightDialog)
{
    ui->setupUi(this);
    move(0,0);
    initialDisplayStyle(styleId);
//#ifdef BUILD_ARM
//    setGeometry(70,128,460,595);
//#endif

    hmiModel = new QStandardItemModel;

    controllerModel = new QStandardItemModel();
}

void CopyRightDialog::initialDisplayStyle(int styleId)
{
    switch (styleId) {
    case 1:
        this->setGeometry(0,0,600,450);
        ui->returnBtn->setGeometry(510,400,70,40);
        break;
    default:
        break;
    }
}

CopyRightDialog::~CopyRightDialog()
{
    delete ui;
}

void CopyRightDialog::updateView()
{
    ui->hmiMainVersion_label->setText(hmiMainVersion);
    ui->conMainVersion_label->setText(controllerMainVersion);

    hmiModel->setHorizontalHeaderItem(0, new QStandardItem(QObject::tr("组件名")));
    hmiModel->setHorizontalHeaderItem(1, new QStandardItem(QObject::tr("组件版本")));
    hmiModel->setHorizontalHeaderItem(2, new QStandardItem(QObject::tr("发布时间")));

    for(int i = 0; i < hmiComponentVersionList.size(); i ++)
    {
        QString str = QString::fromStdString(hmiComponentVersionList[i].componentName);
        hmiModel->setItem(i, 0, new QStandardItem(str));
        str = QString::fromStdString(hmiComponentVersionList[i].componentVersion);
        hmiModel->setItem(i, 1, new QStandardItem(str));
        str = QString::fromStdString(hmiComponentVersionList[i].publishDate);
        hmiModel->setItem(i, 2, new QStandardItem(str));
    }
    ui->hmiComponent_tabView->setModel(hmiModel);
    ui->hmiComponent_tabView->setColumnWidth(0,150);
    ui->hmiComponent_tabView->setColumnWidth(1,100);
    ui->hmiComponent_tabView->setColumnWidth(2,120);

    //ctrl
    controllerModel->setHorizontalHeaderItem(0, new QStandardItem(QObject::tr("组件名")));
    controllerModel->setHorizontalHeaderItem(1, new QStandardItem(QObject::tr("组件版本")));
    controllerModel->setHorizontalHeaderItem(2, new QStandardItem(QObject::tr("发布时间")));

    for(int i = 0; i < controllerComponentVersionList.size(); i ++)
    {
        QString str = QString::fromStdString(controllerComponentVersionList[i].componentName);
        controllerModel->setItem(i, 0, new QStandardItem(str));
        str = QString::fromStdString(controllerComponentVersionList[i].componentVersion);
        controllerModel->setItem(i, 1, new QStandardItem(str));
        str = QString::fromStdString(controllerComponentVersionList[i].publishDate);
        controllerModel->setItem(i, 2, new QStandardItem(str));
    }
    ui->controllerComponent_tabView->setModel(controllerModel);
    ui->controllerComponent_tabView->setColumnWidth(0,150);
    ui->controllerComponent_tabView->setColumnWidth(1,100);
    ui->controllerComponent_tabView->setColumnWidth(2,120);

    ui->hmiComponent_tabView->resizeRowsToContents();
    ui->controllerComponent_tabView->resizeRowsToContents();
}

void CopyRightDialog::changeLanguage()
{
    ui->retranslateUi(this);
}

void CopyRightDialog::on_returnBtn_clicked()
{
    this->hide();
}
